//package com.example.dynamicdatasource.aop;
//
//import com.example.dynamicdatasource.aop.annotation.DataSource;
//import com.example.dynamicdatasource.datasource.DynamicDataSourceContextHolder;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.*;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//
//import java.lang.reflect.Method;
//
///**
// * 多数据源处理
// *
// * @author xxx
// */
//@Aspect
//@Order(1)
//@Component
//@Slf4j
//public class DataSourceAspect {
//    protected Logger logger = LoggerFactory.getLogger(getClass());
//
//    /**
//     * PointCut是指哪些方法需要被执行"AOP"
//     * */
//    @Pointcut("@annotation(com.example.dynamicdatasource.aop.annotation.DataSource)")
//    public void dsPointCut() {
//
//    }
//
//    @Before("dsPointCut()")
//    public void Before(JoinPoint point) throws Throwable {
//        // 获取注解
//        DataSource dataSource = getDataSource(point);
//        log.info("切面获取数据源：" +dataSource.value().name());
//        DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
//    }
//
//    @After("dsPointCut()")
//    public void after(JoinPoint point)  {
//        DynamicDataSourceContextHolder.clearDataSourceType();
//    }
//
//    /**
//     * 获取需要切换的数据源
//     */
//    public DataSource getDataSource(JoinPoint point) {
//        MethodSignature signature = (MethodSignature) point.getSignature();
//        Method method = signature.getMethod();
//        return method.getAnnotation(DataSource.class);
//    }
//}